package com.wbt.huawei.c20221204;

import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.Stack;

public class Java2 {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in, StandardCharsets.UTF_8.name());
        String delDirNameBunch = cin.nextLine();
        int num = Integer.valueOf(delDirNameBunch);
        //cin.nextLine();
        String[] dirTreeLines = new String[num];
        for (int i = 0; i < num; i++) {
            dirTreeLines[i] = cin.nextLine();
        }
        cin.close();
        delDirectorys(delDirNameBunch, dirTreeLines);
    }

    // 待实现函数，在此函数中填入答题代码
    private static int delDirectorys(String delDirNameBunch, String[] dirTreeLines) {
        Stack<String> stack = new Stack<>();
        Stack<Integer> dirLength = new Stack<>();
        int preDir = -1;
        for (int i = 0; i < dirTreeLines.length; i++) {
            String dirStr = dirTreeLines[i];
            int nowDir = 0;
            while (dirStr.contains("|-")){
                dirStr = dirStr.substring(2, dirStr.length());
                nowDir ++;
            }
            if(preDir >= nowDir){
                System.out.print(stack.pop() + " ");
                dirLength.pop();
                while (!dirLength.isEmpty() && !stack.isEmpty() && dirLength.peek() >= nowDir){
                    System.out.print(stack.pop() + " ");
                    dirLength.pop();
                }
            }
            stack.push(dirStr);
            preDir = nowDir;
            dirLength.push(nowDir);
        }
        while ( !stack.isEmpty()){
            if(stack.size() == 1){
                System.out.print(stack.pop());
            }else {
                System.out.print(stack.pop() + " ");
            }


        }
        return 0;
    }
}
